package pers.whj.util.graph;

import pers.whj.util.list.List;
import pers.whj.util.list.SeqList;

public class MinSpanTree<E> {
    private final List<Edge<E>> mList;

    public MinSpanTree() {
        mList = new SeqList<>();
    }

    public void add(Edge<E> edge) {
        mList.insert(edge);
    }

    public boolean remove(Edge<E> edge) {
        return mList.delete(edge);
    }

    public int numOfEdges() {
        return mList.length();
    }

    public Edge<E> get(int index) {
        return mList.get(index);
    }

    public List<Edge<E>> getList() {
        return mList;
    }

    public static class Edge<E> implements Comparable<Edge<E>> {
        public int head;
        public int tail;
        public E weight;

        public Edge(int head, int tail, E weight) {
            this.head = head;
            this.tail = tail;
            this.weight = weight;
        }

        @Override
        @SuppressWarnings({"unchecked"})
        public int compareTo(Edge<E> o) {
            return ((Comparable<E>) weight).compareTo(o.weight);
        }
    }
}